package com.mdd.admin.controller;

import com.mdd.admin.aop.Log;
import com.mdd.admin.service.ILogBusinessUserService;
import com.mdd.admin.validate.commons.IdValidate;
import com.mdd.admin.validate.LogBusinessUserCreateValidate;
import com.mdd.admin.validate.LogBusinessUserUpdateValidate;
import com.mdd.admin.validate.LogBusinessUserSearchValidate;
import com.mdd.admin.validate.commons.PageValidate;
import com.mdd.admin.vo.LogBusinessUserListedVo;
import com.mdd.admin.vo.LogBusinessUserDetailVo;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.validator.annotation.IDMust;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("api/fashi_login_log")
@Api(tags = "商户后台日志管理")
public class LogBusinessUserController {

    @Resource
    ILogBusinessUserService iLogBusinessUserService;

    @GetMapping("/list")
    @ApiOperation(value="商户后台日志列表")
    public AjaxResult<PageResult<LogBusinessUserListedVo>> list(@Validated PageValidate pageValidate,
                                                     @Validated LogBusinessUserSearchValidate searchValidate) {
        PageResult<LogBusinessUserListedVo> list = iLogBusinessUserService.list(pageValidate, searchValidate);
        return AjaxResult.success(list);
    }

    @GetMapping("/detail")
    @ApiOperation(value="商户后台日志详情")
    public AjaxResult<LogBusinessUserDetailVo> detail(@Validated @IDMust() @RequestParam("id") Integer id) {
        LogBusinessUserDetailVo detail = iLogBusinessUserService.detail(id);
        return AjaxResult.success(detail);
    }

    @Log(title = "商户后台日志新增")
    @PostMapping("/add")
    @ApiOperation(value="商户后台日志新增")
    public AjaxResult<Object> add(@Validated @RequestBody LogBusinessUserCreateValidate createValidate) {
        iLogBusinessUserService.add(createValidate);
        return AjaxResult.success();
    }

    @Log(title = "商户后台日志编辑")
    @PostMapping("/edit")
    @ApiOperation(value="商户后台日志编辑")
    public AjaxResult<Object> edit(@Validated @RequestBody LogBusinessUserUpdateValidate updateValidate) {
        iLogBusinessUserService.edit(updateValidate);
        return AjaxResult.success();
    }

    @Log(title = "商户后台日志删除")
    @PostMapping("/del")
    @ApiOperation(value="商户后台日志删除")
    public AjaxResult<Object> del(@Validated @RequestBody IdValidate idValidate) {
        iLogBusinessUserService.del(idValidate.getId());
        return AjaxResult.success();
    }

}
